package org.linlinjava.litemall.db.domain;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * litemall用户
 *
 * @author yliyun
 * @date 2022/09/19
 */
@Data
@TableName("litemall_user")
public class LitemallUser {
    /**
     * 被删除
     */
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    /**
     * 不删除
     */
    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    /**
     * id
     */
    @TableId
    private Integer id;

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 性别
     */
    private Byte gender;

    /**
     * 生日
     */
    private LocalDate birthday;

    /**
     * 最后登录时间
     */
    @TableField(value = "last_login_time", jdbcType = JdbcType.TIMESTAMP, insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime lastLoginTime;

    /**
     * 最后一次登录知识产权
     */
    private String lastLoginIp;

    /**
     * 用户级
     */
    private Byte userLevel;

    /**
     * 昵称
     */
    private String nickname;

    /**
     * 电子邮件
     */
    private String email;

    /**
     * 移动
     */
    private String mobile;

    /**
     * 《阿凡达》
     */
    private String avatar;

    /**
     * weixin openid
     */
    private String weixinOpenid;

    /**
     * 会话密钥
     */
    private String sessionKey;

    /**
     * 状态
     */
    private Byte status;

    /**
     * 可用数量
     */
    private BigDecimal availableAmount;

    /**
     * 点
     */
    @TableField("points")
    private BigDecimal points;

    /**
     * 内部账户
     */
    private Boolean innerAccount;

    /**
     * 添加时间
     */
    private LocalDateTime addTime;

    /**
     * 更新时间
     */
//    @TableField(value = "update_time", jdbcType = JdbcType.TIMESTAMP, insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime updateTime;

    /**
     * 删除
     */
    @TableLogic
    private Boolean deleted;

    /**
     * 级会员id
     */
    @TableField("level_member_id")
    private Integer levelMemberId;

    /**
     * 级成员名
     */
    @TableField("level_member_name")
    private String levelMemberName;


    /**
     * 会员号
     */
    private String membershipNumber;

    /**
     * 邀请码
     */
    private String invitedCode;

    /**
     * 被邀请代码
     */
    private String beenInvitedCode;

    /**
     * 邀请全国矿工工会
     */
    private Integer inviteNum;

    private Integer deletedBy;

    private String appleId;

    private Integer registerType;


    /**
     * 字符串
     *
     * @return {@link String}
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", IS_DELETED=").append(IS_DELETED);
        sb.append(", NOT_DELETED=").append(NOT_DELETED);
        sb.append(", id=").append(id);
        sb.append(", username=").append(username);
        sb.append(", password=").append(password);
        sb.append(", gender=").append(gender);
        sb.append(", birthday=").append(birthday);
        sb.append(", lastLoginTime=").append(lastLoginTime);
        sb.append(", lastLoginIp=").append(lastLoginIp);
        sb.append(", userLevel=").append(userLevel);
        sb.append(", nickname=").append(nickname);
        sb.append(", email=").append(email);
        sb.append(", mobile=").append(mobile);
        sb.append(", avatar=").append(avatar);
        sb.append(", weixinOpenid=").append(weixinOpenid);
        sb.append(", sessionKey=").append(sessionKey);
        sb.append(", status=").append(status);
        sb.append(", availableAmount=").append(availableAmount);
        sb.append(", points=").append(points);
        sb.append(", innerAccount=").append(innerAccount);
        sb.append(", addTime=").append(addTime);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", deleted=").append(deleted);
        sb.append(", levelMemberId=").append(levelMemberId);
        sb.append(", levelMemberName=").append(levelMemberName);
        sb.append(", invitedCode=").append(invitedCode);
        sb.append(", beenInvitedCode=").append(beenInvitedCode);
        sb.append(", inviteNum=").append(inviteNum);
        sb.append("]");
        return sb.toString();
    }

    /**
     * =
     *
     * @param that 那
     * @return boolean
     */
    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        LitemallUser other = (LitemallUser) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
            && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
            && (this.getGender() == null ? other.getGender() == null : this.getGender().equals(other.getGender()))
            && (this.getBirthday() == null ? other.getBirthday() == null : this.getBirthday().equals(other.getBirthday()))
            && (this.getLastLoginTime() == null ? other.getLastLoginTime() == null : this.getLastLoginTime().equals(other.getLastLoginTime()))
            && (this.getLastLoginIp() == null ? other.getLastLoginIp() == null : this.getLastLoginIp().equals(other.getLastLoginIp()))
            && (this.getUserLevel() == null ? other.getUserLevel() == null : this.getUserLevel().equals(other.getUserLevel()))
            && (this.getNickname() == null ? other.getNickname() == null : this.getNickname().equals(other.getNickname()))
            && (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
            && (this.getMobile() == null ? other.getMobile() == null : this.getMobile().equals(other.getMobile()))
            && (this.getAvatar() == null ? other.getAvatar() == null : this.getAvatar().equals(other.getAvatar()))
            && (this.getWeixinOpenid() == null ? other.getWeixinOpenid() == null : this.getWeixinOpenid().equals(other.getWeixinOpenid()))
            && (this.getSessionKey() == null ? other.getSessionKey() == null : this.getSessionKey().equals(other.getSessionKey()))
            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
            && (this.getAvailableAmount() == null ? other.getAvailableAmount() == null : this.getAvailableAmount().equals(other.getAvailableAmount()))
            && (this.getPoints() == null ? other.getPoints() == null : this.getPoints().equals(other.getPoints()))
            && (this.getInnerAccount() == null ? other.getInnerAccount() == null : this.getInnerAccount().equals(other.getInnerAccount()))
            && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
            && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
            && (this.getLevelMemberId() == null ? other.getLevelMemberId() == null : this.getLevelMemberId().equals(other.getLevelMemberId()))
            && (this.getLevelMemberName() == null ? other.getLevelMemberName() == null : this.getLevelMemberName().equals(other.getLevelMemberName()))
            && (this.getInvitedCode() == null ? other.getInvitedCode() == null : this.getInvitedCode().equals(other.getInvitedCode()))
            && (this.getBeenInvitedCode() == null ? other.getBeenInvitedCode() == null : this.getBeenInvitedCode().equals(other.getBeenInvitedCode()))
            && (this.getInviteNum() == null ? other.getInviteNum() == null : this.getInviteNum().equals(other.getInviteNum()));
    }

    /**
     * 散列码
     *
     * @return int
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getGender() == null) ? 0 : getGender().hashCode());
        result = prime * result + ((getBirthday() == null) ? 0 : getBirthday().hashCode());
        result = prime * result + ((getLastLoginTime() == null) ? 0 : getLastLoginTime().hashCode());
        result = prime * result + ((getLastLoginIp() == null) ? 0 : getLastLoginIp().hashCode());
        result = prime * result + ((getUserLevel() == null) ? 0 : getUserLevel().hashCode());
        result = prime * result + ((getNickname() == null) ? 0 : getNickname().hashCode());
        result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
        result = prime * result + ((getMobile() == null) ? 0 : getMobile().hashCode());
        result = prime * result + ((getAvatar() == null) ? 0 : getAvatar().hashCode());
        result = prime * result + ((getWeixinOpenid() == null) ? 0 : getWeixinOpenid().hashCode());
        result = prime * result + ((getSessionKey() == null) ? 0 : getSessionKey().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        result = prime * result + ((getAvailableAmount() == null) ? 0 : getAvailableAmount().hashCode());
        result = prime * result + ((getPoints() == null) ? 0 : getPoints().hashCode());
        result = prime * result + ((getInnerAccount() == null) ? 0 : getInnerAccount().hashCode());
        result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        result = prime * result + ((getLevelMemberId() == null) ? 0 : getLevelMemberId().hashCode());
        result = prime * result + ((getLevelMemberName() == null) ? 0 : getLevelMemberName().hashCode());
        result = prime * result + ((getInvitedCode() == null) ? 0 : getInvitedCode().hashCode());
        result = prime * result + ((getBeenInvitedCode() == null) ? 0 : getBeenInvitedCode().hashCode());
        result = prime * result + ((getInviteNum() == null) ? 0 : getInviteNum().hashCode());
        return result;
    }

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        username("username", "username", "VARCHAR", false),
        password("password", "password", "VARCHAR", true),
        gender("gender", "gender", "TINYINT", false),
        birthday("birthday", "birthday", "DATE", false),
        lastLoginTime("last_login_time", "lastLoginTime", "TIMESTAMP", false),
        lastLoginIp("last_login_ip", "lastLoginIp", "VARCHAR", false),
        userLevel("user_level", "userLevel", "TINYINT", false),
        nickname("nickname", "nickname", "VARCHAR", false),
        email("email", "email", "VARCHAR", false),
        mobile("mobile", "mobile", "VARCHAR", false),
        avatar("avatar", "avatar", "VARCHAR", false),
        weixinOpenid("weixin_openid", "weixinOpenid", "VARCHAR", false),
        sessionKey("session_key", "sessionKey", "VARCHAR", false),
        status("status", "status", "TINYINT", true),
        availableAmount("available_amount", "availableAmount", "DECIMAL", false),
        points("points", "points", "DECIMAL", false),
        innerAccount("inner_account", "innerAccount", "BIT", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        updateTime("update_time", "updateTime", "TIMESTAMP", false),
        deleted("deleted", "deleted", "BIT", false),
        levelMemberId("level_member_id", "levelMemberId", "INTEGER", false),
        levelMemberName("level_member_name", "levelMemberName", "VARCHAR", false),
        invitedCode("invited_code", "invitedCode", "VARCHAR", false),
        beenInvitedCode("been_invited_code", "beenInvitedCode", "VARCHAR", false),
        inviteNum("invite_num", "inviteNum", "INTEGER", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}